package com.bdqn.jwt1.controller;

import com.bdqn.jwt1.entity.ResponseResult;
import com.bdqn.jwt1.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {
    @Autowired
    ProductService productService;

    @PreAuthorize("hasAnyRole('user','manager','admin')")
    @GetMapping("/products")
    public ResponseResult findAllProducts() {
        ResponseResult sr = new ResponseResult();
        sr.setCode(200);
        sr.setFlag(true);
        sr.setData(productService.findAllProducts());
        return sr;
    }
}
